package com.mall.service.item;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.item.MallItemForwardService;
import com.mall.custom.dao.read.MallItemForwardReadMapper;
import com.mall.custom.dao.write.MallItemForwardWriteMapper;
import com.mall.pojo.MallItemForward;
import com.mall.pojo.MallItemForwardExample;
import com.mall.pojo.MallItemForwardExample.Criteria;
import com.mall.query.MallItemForwardQuery;
import com.mall.query.Page;

@Service
public class MallItemForwardServiceImpl implements MallItemForwardService {

	@Autowired
	private MallItemForwardReadMapper mallItemForwardReadMapper;
	@Autowired
	private MallItemForwardWriteMapper mallItemForwardWriteMapper;

	@Override
	public List<MallItemForward> mallItemForwardListByMallItemForwardQuery(MallItemForwardQuery mallItemForwardQuery,
			Page page) {

		MallItemForwardExample mallItemForwardExample = new MallItemForwardExample();
		if (page != null) {
			mallItemForwardExample.setLimit(page.getLength());
			mallItemForwardExample.setStart(page.getBegin());
		}
		Criteria criteria = mallItemForwardExample.createCriteria();
		if (mallItemForwardQuery.getUserId() != null && mallItemForwardQuery.getUserId() > 0) {
			criteria.andUserIdEqualTo(mallItemForwardQuery.getUserId());
		}
		return this.mallItemForwardReadMapper.selectByExample(mallItemForwardExample);
	}

	@Override
	public int insertMallItemForward(MallItemForward mallItemForward) {
		return this.mallItemForwardWriteMapper.insertSelective(mallItemForward);
	}

}
